//
//  WKCommentListCell.m
//  WKMaybell
//
//  Created by 何文虎 on 2018/12/22.
//  Copyright © 2018 何文虎. All rights reserved.
//

#import "WKCommentListCell.h"

@interface WKCommentListCell ()
@property(nonatomic,strong)UIImageView *headerImgView;
@property(nonatomic,strong)UILabel *nameLb;
@property(nonatomic,strong)UILabel *timeLb;
@property(nonatomic,strong)UILabel *contentLb;
@end

@implementation WKCommentListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setup];
    }
    return self;
}

- (void)setup{
    CGFloat margin = 12;
    [self.contentView addSubview:self.headerImgView];
    [self.headerImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(margin);
        make.top.mas_equalTo(margin);
        make.size.mas_equalTo(CGSizeMake(36, 36));
    }];
    
    [self.contentView addSubview:self.nameLb];
    [self.nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_headerImgView.mas_right).offset(margin);
        make.top.mas_equalTo(_headerImgView.mas_top);
        make.size.mas_equalTo(CGSizeMake(80, 14));
    }];
    
    
    [self.contentView addSubview:self.timeLb];
    [self.timeLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_nameLb.mas_left);
        make.top.mas_equalTo(_nameLb.mas_bottom).offset(8);
        make.size.mas_equalTo(CGSizeMake(200, 14));
    }];
    
    [self.contentView addSubview:self.contentLb];
    [self.contentLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(margin);
        make.right.mas_equalTo(-margin);
        make.top.mas_equalTo(_headerImgView.mas_bottom).offset(10);
        make.size.mas_equalTo(CGSizeMake(200, 14));
    }];
    
    _headerImgView.layer.masksToBounds = YES;
    _headerImgView.layer.cornerRadius = 36/2;
    _headerImgView.contentMode = UIViewContentModeScaleAspectFill;
    
    
    _contentLb.numberOfLines = 3;
    _contentLb.preferredMaxLayoutWidth = ScreenWidth - 24;
    [_contentLb sizeToFit];
    
    [_headerImgView sd_setImageWithURL:[NSURL URLWithString:@"http://img1.touxiang.cn/uploads/20120731/31-060351_329.jpg"]];
    _nameLb.text = @"会飞翔的鱼";
    _timeLb.text = @"9-17 12:30";
    
    NSString *content = @"想到了儿时的邻居们，傍";
    
    _contentLb.text = content;
    CGFloat contentHeight = [content boundingRectWithSize:CGSizeMake(ScreenWidth-24, MAXFLOAT) font:PFSC_RegularFont(15) lineSpacing:5].height;
    CGFloat maxcontentHeight = 10+_contentLb.font.lineHeight * 3;
    contentHeight = contentHeight > maxcontentHeight ? maxcontentHeight : contentHeight;
    
    
    [_contentLb mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(contentHeight);
    }];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (UIImageView*)headerImgView{
    if (!_headerImgView) {
        _headerImgView = [[UIImageView alloc]init];
    }
    return _headerImgView;
}

- (UILabel*)nameLb{
    if (!_nameLb) {
        _nameLb = [[UILabel alloc]init];
        _nameLb.textColor = UIColorFromHex(0x3C3C3C);
        _nameLb.font = PFSC_MediumFont(15);
    }
    return _nameLb;
}

- (UILabel*)timeLb{
    if (!_timeLb) {
        _timeLb = [[UILabel alloc]init];
        _timeLb.textColor = UIColorFromHex(0x979797);
        _timeLb.font = PFSC_MediumFont(11);
    }
    return _timeLb;
}

- (UILabel*)contentLb{
    if (!_contentLb) {
        _contentLb = [[UILabel alloc]init];
        _contentLb.textColor = UIColorFromHex(0x3C3C3C);
        _contentLb.font = PFSC_RegularFont(15);
    }
    return _contentLb;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
